
import { EventType } from "../GameSpecial/GameEventType";
import UserService from "../frameSccript/services/userService";
import { sers } from "../frameSccript/system/OverallSystem ";
import EventManager from "./EventManager";
import yyComponent from "./yyComponent";

const {ccclass, property} = cc._decorator;

@ccclass
export default class Scene extends yyComponent {

    // LIFE-CYCLE CALLBACKS:

    // onLoad () {}

    xiayiguanBtn:cc.Node=null

    public daAn= false
    public tiShi= false

    start () {

    }

   public  showVad(delay){
        if(cc.sys.platform == cc.sys.VIVO_GAME){
            let n = ['0afa984540e144498b45b47874e1785d','18978b00f31d4264a3a12be45ede2028']
            console.log('进入')
            setTimeout(() => {
                if(window['qg'] && window['qg'].createCustomAd)
                    var customAd = window['qg'].createCustomAd({
                        posId: n[Math.floor(Math.random()*n.length)],
                        style: {
                            top:200
                        } 
                    });
                console.log('加载1')

                customAd.show()
                console.log('show')

            }, (delay||1) * 1000);
        } 
    }



    saveData(){
        let data = sers().userSrv.getGameLevelData()
        let nowLevel = sers().userSrv.getLevel()
        let gameid = sers().userSrv.getGameId()
        let guanqiaID = sers().userSrv.getGuanqiaID()

        if(UserService.guanqia[+guanqiaID]){
            data.pass.push({
                level:UserService.guanqia[+guanqiaID].level,
                gameId:UserService.guanqia[+guanqiaID].gameId
            })
        }

        if(UserService.guanqia[+guanqiaID+1]){
            data.lock.push({
                level:UserService.guanqia[+guanqiaID+1].level,
                gameId:UserService.guanqia[+guanqiaID+1].gameId
            })
        }else{
            this.xiayiguanBtn.active = false
        }

        sers().userSrv.setGameLevelData(data)
        EventManager.emit(EventType.DirectorEvent.updataLevelList);


        const date = Date.now();
        let ModeDate = sers().localStorageSrv.get(UserService.passlevelDate);
     

        if(ModeDate == null || ModeDate == "" ){
            sers().localStorageSrv.set(UserService.passlevelDate, Date.now());
            sers().userSrv.setpassNumber(0)
        }
        
        let n = sers().userSrv.getpassNumber()
        n++
        sers().userSrv.setpassNumber(n)
        if(n==3){
            let taht = this
            if (window['tt'] && window['tt'].checkShortcut) {
                window['tt'].checkShortcut({
                    success(res) {
                        cc.log("检查快捷方式", res.status);
                        let status = res.status
                        window['tt'].getSystemInfo({
                            success(res) {
                                cc.log('appName:'+res.appName);
                                if (res.appName == "Tt_lite" || res.appName == "Toutiao" || res.appName == "xigua") {
                                   
                                }else{
                                    if(!status.exist){
                                        sers().uiSrv.showtianjiazhuomianPage();
                                    }
                                }
                            },
                            fail(res) {
                                cc.log(`getSystemInfo 调用失败`);
                            },
                        });
    
                    },
                    fail(res) {
                        cc.log("检查快捷方式失败", res.errMsg);
                        taht.emit(EventType.DirectorEvent.showCheck)
                    },
                });
            } 

        }
    }
    
    // update (dt) {}
}
